﻿using MonitorEquipmentFrm.View;
using smforj.common.model;
using smforj.common.service;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Windows.Forms;

namespace MonitorEquipmentFrm
{
    static class Program
    {
        public static ILoginService loginService;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            loginService = new LoginServiceImpl();
            try
            {
                //初始化static信息
                init();
                //登陆 
                //LoginResponse lr = loginService.login("aaa", "bbb");
                //if (lr.isSuccess)
                //{ 
                    //登陆
                    //GlobalCache.loginUser = lr.data; 
                    Application.Run(new MainForm());
                //}
                //else
                //{
                //    MessageBox.Show(lr.message);
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 系统设置参数，目前写在app.conifg中，后台转到后台获取
        /// </summary>
        public static void init()
        {
            //默认地址
            GlobalCache.location = ConfigurationManager.AppSettings["location"];
            //系统id或商家id
            GlobalCache.SysId = ConfigurationManager.AppSettings["sysid"];
            //是否是展示系统
            GlobalCache.isShow = ConfigurationManager.AppSettings["isshow"] == "1" ? true : false;
            //上报时间间隔
            GlobalCache.UTimeSpan = Convert.ToInt32(ConfigurationManager.AppSettings["UTimeSpan"]);
            //读取时间间隔
            GlobalCache.RTimeSpan = Convert.ToInt32(ConfigurationManager.AppSettings["RTimeSpan"]);
            //有效数据间隔
            GlobalCache.TTimeSpan = Convert.ToInt32(ConfigurationManager.AppSettings["TTimeSpan"]);
            //监控类型
            GlobalCache.TType = ConfigurationManager.AppSettings["ttype"]; 
            //数据库信息
            GlobalCache.Conn = new Connection() { ConnString = ConfigurationManager.AppSettings["LocalDB"], Name = "LocalDB" }; 

            //天线
            GlobalCache.AntnnaNumber = Convert.ToInt32(ConfigurationManager.AppSettings["AntnnaNumber"])-1;


            //API Url
            GlobalCache.BaseUrl = ConfigurationManager.ConnectionStrings["baseurl"].ConnectionString;

            GlobalCache.LogoutUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["logout"].ConnectionString);
            GlobalCache.LoginUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["login"].ConnectionString);


            GlobalCache.RankingUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["getranking"].ConnectionString);
            GlobalCache.CommodityUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["getcommodity"].ConnectionString);
            GlobalCache.CommodityListUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["getcommoditys"].ConnectionString);
            GlobalCache.CommodityTypeListUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["getcommoditytype"].ConnectionString);

            GlobalCache.UploadRecommendUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["uploadrecommend"].ConnectionString);

            GlobalCache.PreferenceListUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["preference"].ConnectionString);
            GlobalCache.UploadPerenceUrl = (GlobalCache.BaseUrl + ConfigurationManager.ConnectionStrings["uploadpreference"].ConnectionString);

            

        }
    }
}
